<template>
  <div class="profile">
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
    <el-form-item label="满" prop="full">
      <el-input v-model="ruleForm.full"></el-input>
    </el-form-item>
      <el-form-item label="减" prop="decrease">
        <el-input v-model="ruleForm.decrease"></el-input>
      </el-form-item>

    <el-form-item>
      <el-button type="primary" @click="submitForm('ruleForm')">立即发布</el-button>
      <el-button @click="resetForm('ruleForm')">重置</el-button>
    </el-form-item>
  </el-form>
   </div>

</template>

<script>
  import {requestPost} from "../../../../network/request";

  export default {
    data() {
      return {
        ruleForm: {
          full: '',
          decrease: '',
        },
        rules: {
          full: [
            { required: true, message: '请输入满金额', trigger: 'blur' },
          ],
          decrease: [
            { required: true, message: '请输入减金额', trigger: 'blur' },
          ],
        }
      };
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            requestPost({
              //增加活动api
              url: 'activity/add',
              data: {
                full: this.ruleForm.full,
                decrease: this.ruleForm.decrease,
              }
            }).then(res=>{
              alert("添加成功");
              this.$router.replace("/user/userList");
            });
          } else {
            alert("添加失败");
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  }
</script>
<style>
  .demo-ruleForm{
    width: 70%;
  }
  .profile{
    text-align: center;
    margin: 0 auto;
    width: 50%;
    padding-top: 5%;
  }
</style>
